package com.example.lenovo.newgift.welcome;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v4.widget.TextViewCompat;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.lenovo.newgift.MainActivity;
import com.example.lenovo.newgift.R;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ThreadFactory;

/**
 * Created by Risky57 on 2017/6/27.
 */

public class WelcomeActivity extends Activity {

    private int count = 5;
    private TextView mTextSkip;
    private CountDownTimer mTimer;

    @Override
    protected void onCreate (@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        mTextSkip = (TextView) findViewById(R.id.text_skip);

        mTimer = new CountDownTimer(count * 1000 + 500, 1000) {
            @Override
            public void onTick (long millisUntilFinished) {
                mTextSkip.setText(count-- + "秒");
            }

            @Override
            public void onFinish () {
                toMainActivity();
            }
        };
        mTimer.start();

    }

    public void onSkip (View view) {
        mTimer.cancel();
        toMainActivity();
    }

    private void toMainActivity(){
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

}
